package com.ctshk.sapp.hotel.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.dto.*;
import com.ctshk.rpc.hotel.dto.booking.HotelProductUnitPriceDTO;
import com.ctshk.rpc.hotel.req.*;
import com.ctshk.rpc.hotel.req.booking.HotelApprovalReq;
import com.ctshk.rpc.hotel.req.booking.HotelProductUnitPriceReq;
import com.ctshk.rpc.hotel.service.IHotelProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 酒店产品 前端控制器
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-03
 */
@RestController
@Api(value = "酒店产品", tags = "酒店产品")
@RequestMapping("/hotel/product")
public class HotelProductController extends BaseController {
    @DubboReference
    private IHotelProductService hotelProductService;

    @ApiOperation(value="酒店产品查询列表", notes="酒店产品查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "酒店分页查询列表", operDesc = "酒店分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<HotelProductListDTO>> queryHotelLineList(@RequestBody @Valid HotelListProductReq req) {
        PageResponse<HotelProductListDTO> response = hotelProductService.queryList(req, getCurrentUserId());
        return Result.success(response);
    }

    @ApiOperation(value="酒店预订产品查询列表", notes="酒店预订产品查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "酒店预订产品查询列表", operDesc = "酒店预订产品查询列表")
    @PostMapping("/queryReservetionList")
    public Result<PageResponse<RecommendedHotelDTO>> queryReservetionList(@RequestBody @Valid HotelReservertionReq req) {
        PageResponse<RecommendedHotelDTO> response = hotelProductService.queryReservetionList(req);
        //还需要将价格全部设置加幅。
        //未做
        return Result.success(response);
    }

    @ApiOperation(value="新增酒店产品", notes="新增酒店产品")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增酒店产品", operDesc = "新增酒店产品")
    @PostMapping("/save/hotelProduct")
    public Result saveHotelProduct(@RequestBody @Valid HotelProductDataReq hotelProductDataReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.saveHotelProduct(hotelProductDataReq,user);
    }

    @ApiOperation(value="新增酒店产品预约设置", notes="新增酒店产品预约设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增酒店产品", operDesc = "新增酒店产品")
    @PostMapping("/save/saveHotelProductResevertion")
    public Result saveHotelResevertionProduct(@RequestBody @Valid HotelProductDataReq hotelProductDataReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.updateReservation(hotelProductDataReq,user);
    }

    @ApiOperation(value="发起审批", notes="发起酒店审批")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "发起审批", operDesc = "发起酒店审批")
    @GetMapping("/approval/start/{productId}")
    public Result start(@PathVariable Long productId) {
        TokenUser user = getCurrentUser(getRequest());
        return Result.success(hotelProductService.approvalStart(productId, user.getId()));
    }

    @ApiOperation(value="审核审批", notes="酒店审核")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "酒店审核", operDesc = "发起酒店审核")
    @PostMapping("/approval/check")
    public Result check(@RequestBody @Valid HotelApprovalReq req) {
        TokenUser user = getCurrentUser(getRequest());
        return Result.success(hotelProductService.approvalCheck(req.getApprovalId(), req.getBusinessId(), user.getId(), req.getStatus(), req.getComments()));
    }

    @ApiOperation(value="返回后产品修改", notes="返回后产品修改")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增酒店产品", operDesc = "新增酒店产品")
    @PostMapping("/save/updateHotelProduct")
    public Result updateHotelProduct(@RequestBody @Valid HotelProductDataReq hotelProductDataReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.updateHotelProduct(hotelProductDataReq,user);
    }

    @ApiOperation(value = "查询酒店产品详情", notes = "查询酒店产品详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询酒店产品详情", operDesc = "查询酒店产品详情")
    @GetMapping(value = "/detail/{id}")
    public Result<HotelProductDTO> queryDetail(@PathVariable Long id) {
        HotelProductDTO hotelProductDTO = hotelProductService.queryDetail(id);
        return Result.success(hotelProductDTO);
    }

    @ApiOperation(value = "查询酒店品牌下的酒店信息", notes = "查询酒店品牌下的酒店信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询酒店品牌下的酒店信息", operDesc = "查询酒店品牌下的酒店信息")
    @PostMapping(value = "/getHotelNameInfo")
    public Result<List<HotelNameInfoDTO>> getHotelNameInfo(@RequestBody @Valid HotelNameAndIdReq hotelNameAndIdReq) {
        List<HotelNameInfoDTO> hotelNameInfoDTO = hotelProductService.getHotelInfoByBrand(hotelNameAndIdReq);
        return Result.success(hotelNameInfoDTO);
    }

    @ApiOperation(value = "查询酒店下的酒店房型信息", notes = "查询酒店下的酒店房型信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询酒店下的酒店房型信息", operDesc = "查询酒店下的酒店房型信息")
    @PostMapping(value = "/getHotelRoomNameInfo")
    public Result<List<HotelNameInfoDTO>> getHotelRoomNameInfo(@RequestBody @Valid HotelNameAndIdReq hotelNameAndIdReq) {
        List<HotelNameInfoDTO> hotelNameInfoDTO = hotelProductService.getHotelRoomNameInfo(hotelNameAndIdReq);
        return Result.success(hotelNameInfoDTO);
    }

    @ApiOperation(value = "批量设置", notes = "批量设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "有效无效设置", operDesc = "有效无效设置")
    @PostMapping(value = "/batchSetting")
    public Result batchSetting(@RequestBody @Valid BatchHotelProductInfoReq batchHotelProductInfoReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.batchSettingHotel(batchHotelProductInfoReq,user);

    }

    @ApiOperation(value = "有效无效设置", notes = "有效无效设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "有效无效设置", operDesc = "有效无效设置")
    @GetMapping(value = "/setValid/{id}")
    public Result setValid(@PathVariable Long id) {
        return hotelProductService.setValid(id,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "酒店预订详情页面", notes = "酒店预订详情页面")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "酒店预订详情页面", operDesc = "酒店预订详情页面")
    @GetMapping(value = "/bookingHotel/{hotelId}")
    public Result bookingHotel(@PathVariable Long hotelId) {
        TokenUser user = getCurrentUser(getRequest());
        HotelReservestionStockAndPriceDTO hotelNameInfoDTO = hotelProductService.bookingHotel(hotelId,user);
        return Result.success(hotelNameInfoDTO);
    }

    @ApiOperation(value = "API设置", notes = "API设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "API设置", operDesc = "API设置")
    @PostMapping(value = "/setApi")
    public Result setApi(@RequestBody @Valid HotelProductSetReq hotelProductSetReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.setApi(hotelProductSetReq,user);
    }

    @ApiOperation(value = "推荐设置", notes = "推荐设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "推荐设置", operDesc = "推荐设置")
    @PostMapping(value = "/setRecommended")
    public Result setRecommended(@RequestBody @Valid HotelRecommendedReq hotelRecommendedReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.setRecommended(hotelRecommendedReq,user);
    }

    @ApiOperation(value = "查询酒店推荐列表", notes = "查询酒店推荐列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询酒店推荐列表", operDesc = "查询酒店表推荐列表")
    @PostMapping(value = "/recommendedHotel/list")
    public Result<List<RecommendedHotelDTO>> queryRecommendedHotel() {
        Long userId = getCurrentUser(getRequest()).getId();
        List<RecommendedHotelDTO> reservationHotelDTOList = hotelProductService.queryRecommendedHotel(userId);
        return Result.success(reservationHotelDTOList);
    }

    @ApiOperation(value = "新增-编辑提交审批", notes = "新增-编辑提交审批")
    @GetMapping(value = "/update/approvalStatus/{id}")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "酒店产品提交审批", operDesc = "酒店产品提交审批")
    public Result submit(@PathVariable("id") Long id) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.submit(id,user);
    }

    @ApiOperation(value="修改审核通过酒店产品", notes="修改审核通过酒店产品")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改审核通过酒店产品", operDesc = "修改审核通过酒店产品")
    @PostMapping("/approved/update")
    public Result updateApprovedHotelProduct(@RequestBody @Valid HotelProductReq hotelProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.updateApprovedHotelProduct(hotelProductReq,user);
    }

    @ApiOperation(value="修改审核不通过酒店产品", notes="修改审核不通过酒店产品")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改审核不通过酒店产品", operDesc = "修改审核不通过酒店产品")
    @PostMapping("/unapproved/update")
    public Result updateUnapprovedHotelProduct(@RequestBody @Valid HotelProductReq hotelProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelProductService.updateUnapprovedHotelProduct(hotelProductReq,user);
    }

    @ApiOperation(value="预订中心-获取产品单价", notes="获取产品单价")
    @OperationLogAnnotation(operModul = OperationLogModel.HOTEL, operType = OperationLogType.QUERY, operTitle = "获取产品单价", operDesc = "预订中心-获取产品单价")
    @PostMapping("/booking/unit-price")
    public Result<HotelProductUnitPriceDTO> unitPrice(@RequestBody @Valid HotelProductUnitPriceReq req) {
        return hotelProductService.queryUnitPrice(req,getCurrentUser(getRequest()).getId());
    }
}
